package com.aaa.tomcat;

import lombok.Data;

import java.io.IOException;
import java.io.InputStream;

/**
 * @author ：Teacher陈
 * @date ：Created in 2021/1/20 10:22
 * @description：自定义的请求类
 * @modified By：
 * @version: 1.0
 */
@Data
public class RequestAAA {
    private String method;
    private String url;
    private InputStream inputStream;

    public RequestAAA(InputStream inputStream) throws Exception {
        byte[] buf= new byte[1024];
        //定义一个请求字符串
        String  requestStr="";
        //处理inputStream，获取请求方式和请求地址
        int count=0;
        if((count=inputStream.read(buf))>0){
            requestStr= new String(buf,0,count);
        }
        /**
         * GET /aaa/xxx HTTP/1.1
         * Host: localhost:8080
         */
        //获取第一行
        String head = requestStr.split("\n")[0];
         this.method = head.split("\\s")[0];
         this.url=head.split("\\s")[1];
    }
}
